<template>
    <div>
        <h2>修改会员级别</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>会员级别名称</td>
                    <td>
                        <input type="text" v-model="quertinfo.Name">
                    </td>
                </tr>

                <tr>
                    <td>累计最低消费额（元）</td>
                    <td>
                        <input type="text" v-model="quertinfo.MinMoney">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" class="btn btn-primary" @click="upd">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();
import moment from 'moment';
//反填
onMounted(()=>{
    getLevel();
})
const getLevel=()=>{
    axios({
        method:'get',
        url:'/api/Week/FanTian',
        params:{
            id:route.query.id
        }
    })
    .then(res=>{
        console.log(res);
        {
            quertinfo.Name=res.data.Name;
            quertinfo.MinMoney=res.data.MinMoney;
        }
    })
}

let quertinfo=reactive({
  "Id":route.query.id,
  "Name": "",
  "MinMoney": ''
})

const upd=()=>{
    //验证有效性
    if(quertinfo.Name==""){
        alert('名称不能为空');
        return;
    }
    if(quertinfo.MinMoney==""){
        alert('累计最低消费金额不能为空');
        return;
    }
    let reg=/^\d+$/g;
    if(!reg.test(quertinfo.MinMoney)){
        alert('累计最低消费金额只能是整数');
        return;
    }

    //返回网络请求
    axios({
        method:'put',
        url:'/api/Week/Updlevel',
        data:quertinfo
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('名称重复');
            return;
        }
        if(res.data>0){
            alert('成功');
            router.push('/levelshow')
        }
        else{
            alert('失败');
        }
    })

}

</script>

<style scoped>

</style>